package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.service.IIndexService;
import com.mdd.front.service.album.IAlbumService;
import com.mdd.front.service.goods.IGoodsService;
import com.mdd.front.validate.PageParam;
import com.mdd.front.vo.article.ArticleListVo;
import com.mdd.front.vo.goods.GoodsDetailVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 主页管理
 */
@RestController
@RequestMapping("/api")
public class IndexController {

    @Resource
    IIndexService iIndexService;

    @Resource
    IAlbumService iAlbumService;

    @Resource
    private IGoodsService iGoodsService;

    /**
     * 首页
     *
     * @return Object
     * @author fzr
     */
    @GetMapping("/index")
    public Object index() {
        Map<String, Object> detail = iIndexService.index();
        return AjaxResult.success(detail);
    }

    /**
     * 首页
     *
     * @return Object
     * @author fzr
     */
    @GetMapping("/index/index")
    public Object indexCity(@RequestParam(value = "cityId", required = false) Long cityId) {
        Map<String, Object> detail = iIndexService.indexCity(cityId);
        return AjaxResult.success(detail);
    }

    /**
     * @return java.lang.Object
     * @Author slien
     * @Description 用户访问量
     * @Date 15:14 2022/12/4
     * @Param [cityId]
     **/
    @GetMapping("/index/visit")
    public void visit(@RequestParam("terminal") Integer terminal) {
        iIndexService.visit(terminal);
    }

    /**
     * 装修
     *
     * @param id 主键
     * @return Object
     * @author fzr
     */
    @GetMapping("/decorate")
    public Object decorate(@Validated @IDMust() @RequestParam("id") Integer id) {
        Map<String, Object> detail = iIndexService.decorate(id);
        return AjaxResult.success(detail);
    }

    /**
     * 配置
     *
     * @return Object
     * @author fzr
     */
    @GetMapping("/config")
    public Object config() {
        Map<String, Object> map = iIndexService.config();
        return AjaxResult.success(map);
    }

    /**
     * 协议
     *
     * @param type 类型 service=服务协议,privacy=隐私协议
     * @return Object
     * @author fzr
     */
    @GetMapping("/policy")
    public Object policy(@RequestParam String type) {
        Map<String, String> map = iIndexService.policy(type);
        return AjaxResult.success(map);
    }

    /**
     * 热搜
     *
     * @return Object
     * @author fzr
     */
    @GetMapping("/hotSearch")
    public Object hotSearch() {
        List<String> list = iIndexService.hotSearch();
        return AjaxResult.success(list);
    }

    /**
     * 搜索
     *
     * @return Object
     * @author fzr
     */
    @GetMapping("/search")
    public Object search(@Validated PageParam pageParam,
                         @RequestParam Map<String, String> params) {
        PageResult<ArticleListVo> list = iIndexService.search(pageParam, params);
        return AjaxResult.success(list);
    }

    /**
     * 获取首页背景图
     * @return 返回首页背景图或者限时商品背景图的地址
     * type
     */
    @GetMapping("/getIndexImage")
    public String getIndexImage(@RequestParam(value = "type",defaultValue = "0")Integer type) {
        return iAlbumService.getIndexUrl(type);
    }

    /**
     * 获取今日推荐
     * @return 返回服务详情
     */
    @GetMapping("/getTodaySpecials")
    public GoodsDetailVo getTodaySpecials() {
        return iGoodsService.getTodaySpecials();
    }
}
